package com.csdj.service;

import com.csdj.mapper.ConfigMapper;
import com.csdj.pojo.Config;
import com.csdj.pojo.ConfigExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class ConfigServiceImpl implements ConfigService{
    @Resource
    private ConfigMapper mapper;
    @Override
    public Integer insertConfig(Config config) {

        return mapper.insertSelective(config);
    }

    @Override
    public Integer updateConfig(Config config) {
        return mapper.update(config);
    }

    @Override
    public List<Config> selectAllByType(String type) {
        ConfigExample example=new ConfigExample();
        example.createCriteria().andTypeEqualTo(type);
        List<Config> configs = mapper.selectByExample(example);
        System.out.println(configs);
        return configs;
    }



    @Override
    public PageInfo<Config> selectPage(Integer pageNo) {
        PageHelper.startPage(pageNo,2);
        ConfigExample example=new ConfigExample();
        List<Config> configs = mapper.selectByExample(example);
        PageInfo<Config> pageInfo = new PageInfo<>(configs);
        return pageInfo;
    }

    @Override
    public List<Config> selectAllByTypeAndKey(String type, String key) {
        ConfigExample example=new ConfigExample();
        example.createCriteria().andKeyEqualTo(key).andTypeEqualTo(type);
        return mapper.selectByExample(example);
    }

}
